package com.buba.record.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.pojo.record.NucleicReport;
import com.buba.pojoVo.MedicalRecordsVo;
import com.buba.record.service.impl.NucleicReportServiceImpl;
import com.buba.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 核酸报告表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-06-09
 */
@Slf4j
@RestController
@RequestMapping("/record/nucleic-report")
public class NucleicReportController {

    @Autowired
    private NucleicReportServiceImpl nucleicReportService;

    /*
     * @Author: 张庆威
     * @Description: (根据就诊人id 查询该就诊人的所有核酸报告)
     * @Date: 10:26 2022/6/23
     * @Param: [patientId]
     * @return: com.buba.utils.R
     **/
    @GetMapping("/getHesuans/{patientId}")
    public R getHesuans(@PathVariable("patientId") Integer patientId) {
        log.info("patientId:::::::" + patientId);
        QueryWrapper<NucleicReport> wrapper = new QueryWrapper<>();
        wrapper.eq("of_patient_id", patientId);
        List<NucleicReport> list = nucleicReportService.list(wrapper);
        //List<MedicalRecordsVo> list = nucleicReportService.getHesuans(patientId);

        if (list != null) {
            return R.ok().data("list", list);
        } else {
            return R.error();
        }
    }


    //添加核酸报告
    @PostMapping("/addnucleicReport")
    public R addnucleicReport(@RequestBody NucleicReport nucleicReport){
        nucleicReport.setCreateTime(new Date());
        nucleicReport.setUpdateTime(new Date());
        nucleicReport.setDeleteFlag("0");
        boolean save=nucleicReportService.save(nucleicReport);
        //修改核酸预约状态
//            int i=nucleicReportService.updatehsState(nucleicAcid);
        if(save==true){
            return R.ok().data("ok","添加成功");
        }else {
            return R.ok().data("error","添加失败");
        }
    }


}

